<template>
	<view class="singleItem">
		<view class="top">
			<view class="goBackButton" @click="goBack()">
				<image style="width: 100%;height: 100%;" src="../../static/icons/Iconly_Light_Arrow - Left@1x.png"
					mode="center">
				</image>
			</view>
			<view class="likeButton">
				<image style="width: 100%;height: 100%;" src="../../static/icons/Iconly_Light_Heart@1x.png"
					mode="center"></image>
			</view>
		</view>

		<view class="swiper">
			<swiper @change="swiperChange" style="height: 100%;" circular :indicator-dots="false" :autoplay="false"
				:interval="3000" :duration="500">
				<swiper-item style="display: flex;align-items: center;" v-for="(item, index) in swiperItem"
					:key="index">
					<image :src="item.image" class="swiper-image" mode="center" />
				</swiper-item>
			</swiper>
		</view>

		<view class="indicator">
			<view v-for="(item,index) in swiperItem" class="indicatorItemBox"
				:class="{indicatorItemBoxActive:swiperCurrentIndex === index}">
				<view class="indicatorItem" :class="{indicatorItemActive:swiperCurrentIndex === index}">

				</view>
			</view>
		</view>


		<view class="goodInfo">
			<view class="goodName">
				2020 Apple iPad Air 10.9"
			</view>


			<view class="colorsSelector">
				<view class="title">
					Colors
				</view>

				<view class="colorsSelectorItemBox">
					<view @click="selectColor(index)" v-for="(item,index) in colorsData" class="colorsSelectorItem"
						:class="{'colorsSelectorItemActive':selectColorIndex === index}">
						<view class="color" :style="{backgroundColor:item.color}">

						</view>

						<view class="colorName">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>



			<view class="desc">
				<view class="title">
					Get Apple TV+ free for a year
				</view>

				<view class="detail">
					Available when you purchase any new iPhone, iPad, iPod Touch, Mac or Apple TV, £4.99/month after
					free trial.
				</view>
			</view>

			<view class="total">
				<view class="text">
					Total
				</view>

				<view class="num">
					$ 579
				</view>
			</view>


			<view class="addButton" @click="addBasket">
				<view class="text">
					Add to basket
				</view>
			</view>


		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';

	const testContent = ref("")



	const swiperItem = ref([{
			image: '../../static/images/singleItem/swiper1.png'
		},
		{
			image: '../../static/images/singleItem/swiper2.png'
		},
		{
			image: '../../static/images/singleItem/swiper1.png'
		},
	])

	// 轮播图当前索引
	const swiperCurrentIndex = ref(0)

	// 轮播图滑动
	const swiperChange = (e) => {
		swiperCurrentIndex.value = e.detail.current
	}


	// 返回上一页
	const goBack = () => {
		uni.navigateBack()
	}

	// 颜色选择数据
	const colorsData = ref([{
			color: "rgba(116, 133, 193, 1)",
			name: "Sky Blue"
		},
		{
			color: "rgba(201, 161, 156, 1)",
			name: "Rose Gold"
		},
		{
			color: "rgba(161, 200, 155, 1)",
			name: "Green"
		},
		{
			color: "rgba(161, 200, 155, 1)",
			name: "Green"
		}
	])



	// 颜色选择的索引
	const selectColorIndex = ref(0)

	// 选择颜色
	const selectColor = (index) => {
		selectColorIndex.value = index
		console.log(selectColorIndex.value);
	}


	// 添加到购物车跳转购物车
	const addBasket = () => {
		uni.navigateTo({
			url: '/pages/basket/basket'
		})
	}
</script>



<style scoped lang="scss">
	.singleItem {
		width: 100vw;
		min-height: 100vh;
		height: 100%;
		background-color: rgba(246, 246, 249, 1);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: start;

		.top {
			margin-top: 120rpx;
			width: 100%;
			padding: 0 58rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.goBackButton,
			.likeButton {
				width: 48rpx;
				height: 48rpx;
			}
		}

		.swiper {
			margin-top: 16rpx;
			height: 460rpx;
			width: 100%;
			// background-color: beige;

			.swiper-image {
				// width: 100%;
				height: 100%;
				margin: 0 auto;
			}
		}


		.indicator {
			width: fit-content;
			height: fit-content;
			display: flex;
			justify-content: space-between;
			align-items: center;
			gap: 24rpx;

			.indicatorItemBox {
				padding: 8rpx;
				border-radius: 50%;

				&.indicatorItemBoxActive {
					border: 1px solid rgba(89, 86, 233, 1);
				}


				.indicatorItem {
					height: 16rpx;
					width: 16rpx;
					background-color: rgba(196, 196, 196, 1);
					border-radius: 50%;
				}


				.indicatorItemActive {
					background-color: rgba(89, 86, 233, 1);
				}
			}
		}

		.goodInfo {
			margin-top: 36rpx;
			flex: 1;
			width: 100vw;
			border-top-right-radius: 40rpx;
			border-top-left-radius: 40rpx;
			background: rgba(255, 255, 255, 1);
			box-shadow: 0px 4px 30px rgba(0, 0, 0, 0.06);
			display: flex;
			align-items: center;
			justify-content: start;
			flex-direction: column;
			padding: 0 60rpx;

			.goodName {
				margin-top: 58rpx;
				font-size: 50rpx;
				font-weight: 600;
				letter-spacing: 0px;
				// line-height: 0px;
				color: rgba(0, 0, 0, 1);
			}

			.colorsSelector {
				width: 100%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: start;
				gap: 20rpx;

				.title {
					font-size: 34rpx;
					font-weight: 700;
					letter-spacing: 0px;
					line-height: 19.96px;
					color: rgba(0, 0, 0, 1);
				}

				.colorsSelectorItemBox {
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					flex-wrap: wrap;
					gap: 2rpx;


					.colorsSelectorItemActive {
						border: 1px solid rgba(89, 86, 233, 1) !important;
					}


					.colorsSelectorItem {
						width: 208rpx;
						height: 80rpx;
						border-radius: 20rpx;
						background: rgba(255, 255, 255, 1);
						border: 1px solid rgba(227, 227, 227, 1);
						box-shadow: 0px 4px 14px rgba(0, 0, 0, 0.06);
						display: flex;
						align-items: center;
						justify-content: space-around;



						&:active {
							opacity: 0.8;
						}

						.color {
							width: 32rpx;
							height: 32rpx;
							border-radius: 50%;
						}

						.colorName {
							font-size: 24rpx;
							font-weight: 700;
							letter-spacing: 0px;
							line-height: 14.09px;
							color: rgba(0, 0, 0, 1);
						}
					}
				}
			}


			.desc {
				margin-top: 60rpx;
				width: 100%;

				.title {
					font-size: 34rpx;
					font-weight: 700;
					width: 100%;
					overflow: hidden;
					text-overflow: ellipsis;
					text-align: start;
				}

				.detail {
					opacity: 0.5;
					/** 文本1 */
					font-size: 30rpx;
					font-weight: 400;
				}
			}

			.total {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				margin-top: 60rpx;

				.text {
					font-size: 34rpx;
					font-weight: 400;
					letter-spacing: 0px;
					line-height: 19.92px;
				}

				.num {
					font-size: 44rpx;
					font-weight: 700;
					letter-spacing: 0px;
					line-height: 25.83px;
					color: rgba(89, 86, 233, 1);
				}
			}


			.addButton {
				margin-top: 40rpx;
				width: 628rpx;
				height: 140rpx;
				border-radius: 20rpx;
				background: rgba(89, 86, 233, 1);
				box-shadow: 0px 20px 40px rgba(0, 0, 0, 0.1);
				display: flex;
				align-items: center;
				justify-content: center;


				&:active {
					opacity: 0.8;
				}

				.text {
					font-size: 40rpx;
					font-weight: 700;
					letter-spacing: 0px;
					line-height: 23.48px;
					color: rgba(246, 246, 249, 1);
				}
			}
		}
	}
</style>